package com.biz.primus.ms.base.config;

import com.biz.primus.ms.base.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;
import redis.clients.jedis.ShardedJedisPool;

/**
 *
 *
 *
 * @author yanweijin
 * @date 2017/9/11
 */
@Configuration
@Component
@Import({
		JedisConfiguration.class,
		Swagger2Configuration.class
})
public class BaseConfiguration {


	@Autowired
	private ShardedJedisPool jedisPool;

	@Bean
	IdxFactory idxFactory(){
		return new RedisIdxFactoryImpl(jedisPool);
	}

	@Bean
	IdService idService(){
		return new IdService(idxFactory());
	}

	@Bean
	TransactionOptDelayer redisOptDelayer(){
		return new TransactionOptDelayer();
	}

	@Bean
	DataSyncListener dataSyncListener(){
		return new DataSyncListener();
	}

	@Bean
	SequenceGenerator sequenceGenerator(){
		SequenceGenerator sequenceGenerator = new SequenceGenerator();
		sequenceGenerator.setShardedJedisPool(jedisPool);
		return sequenceGenerator;
	}


}
